package com.gxa.jjty.cjr.service.impl;

import com.gxa.jjty.cjr.mapper.BillMapper;
import com.gxa.jjty.cjr.mapper.CjrMapper;
import com.gxa.jjty.cjr.service.BillService;
import com.gxa.jjty.cjr.service.CjrUserService;
import com.gxa.jjty.core.exception.BusinessException;
import com.gxa.jjty.core.pojo.Bill;
import com.gxa.jjty.core.pojo.CjrUser;
import com.gxa.jjty.core.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author NITRO
 */
@Service("billService")
public class BillServiceImpl extends BaseServiceImpl<Bill>  implements BillService {

    @Autowired
    BillMapper billMapper;
    @Autowired
    private CjrUserService cjrUserService;
    @Override
    public void paid(Double money,String number) throws BusinessException {
        Bill bill=new Bill();
        bill.setExpend(money);
        bill.setIncome(0.0);
        bill.setRiseTime(new Date());
        bill.setOrderNumber(number);
        bill.setBalance(billMapper.selectDayBalance().get(0).getBalance()-money);
        bill.setType("支出");
        billMapper.insert(bill);
    }

    @Override
    public void income(Double money,String number) throws BusinessException {
        Bill bill=new Bill();
        bill.setIncome(money);
        bill.setExpend(0.0);
        bill.setRiseTime(new Date());
        bill.setOrderNumber(number);
        bill.setBalance(billMapper.selectDayBalance().get(0).getBalance()+money);
        bill.setType("收入");
        billMapper.insert(bill);
    }
}
